# -*-coding:utf-8 -*-

"""
# File       : getDouban.py
# Time       ：2022/10/13 下午5:10
# Author     ：puppet
# version    ：python 3.8.1
# Description：
"""
import requests
from bs4 import BeautifulSoup
import re

def getDoubanData():
    doubanUrl = 'https://movie.douban.com/chart'
    headers = {
        "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'
    }
    res = requests.post(url=doubanUrl, headers=headers)
    resultList = []
    if res.status_code == 200:
        soup = BeautifulSoup(res.text, "html.parser")
        items = soup.find_all('table')
        for item in items:
            moviename = item.find_all('a')[0].get('title')
            link = item.find_all('a')[0].get('href')
            actors = item.find_all('p')[0].string
            score = item.find_all('span', class_='rating_nums')[0].string
            commentsNumtemp = item.find_all('span', class_='pl')[0].string
            commentsNum = int(re.findall(r'\d{1,8}', commentsNumtemp)[0])
            tempList = [moviename, link, score, commentsNum, actors]
            resultList.append(tempList)
    return resultList
